package cn.enilu.flash.api.controller.h5;

import cn.enilu.flash.bean.vo.front.Ret;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.task.MoneyInfoVo;
import cn.enilu.flash.security.JwtUtil;
import cn.enilu.flash.service.task.MoneyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/h5")
public class H5MoneyInfoController {
    @Autowired
    private MoneyInfoService moneyInfoService;
    /**
     * 获取取资金明细
     * param limit:
    * @param type: 类型：1任务奖励，2余额提现，3任务支付，4任务退款,5余额充值
    */
    @GetMapping("getMoneyInfo")
    public Ret getMoneyInfo( @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit,
                             @RequestParam(defaultValue = "-1")Integer type){
        StringBuffer sql = new StringBuffer();
        sql.append("Select * from t_money_info where create_by = "+ JwtUtil.getUserId() +" ");
        if(type != -1){
            sql.append(" and type = "+type+" ");
        }
        sql.append(" order by create_time desc ");
        if(page<1) page = 1;
        int start = (page-1)*limit;
        sql.append("LIMIT "+start+","+limit+" ");
        List<MoneyInfoVo> moneyInfos = moneyInfoService.queryBySql(sql.toString());
        return Rets.success(moneyInfos);
    }
}
